#!/bin/bash
#运行脚本之前先确定bootstrap.kubeconfig从master复制过来了。比如
#scp /usr/local/kubernetes/ssl/bootstrap.kubeconfig root@192.168.1.208:/usr/local/kubernetes/ssl/
#脚本运行命令： ./kubelet.sh 192.168.1.206 10.10.10.2
NODE_ADDRESS=${1:-"192.168.1.206"}
DNS_SERVER_IP=${2:-"10.10.10.2"}

cat <<EOF >/usr/local/kubernetes/cfg/kubelet

KUBELET_OPTS="--logtostderr=true \\
--v=4 \\
--address=${NODE_ADDRESS} \\
--hostname-override=${NODE_ADDRESS} \\
--kubeconfig=/usr/local/kubernetes/ssl/kubelet.kubeconfig \\
--experimental-bootstrap-kubeconfig=/usr/local/kubernetes/ssl/bootstrap.kubeconfig \\
--cert-dir=/usr/local/kubernetes/ssl \\
--allow-privileged=true \\
--cluster-dns=${DNS_SERVER_IP} \\
--cluster-domain=cluster.local \\
--fail-swap-on=false \\
--network-plugin=cni \\
--pod-infra-container-image=k8s.gcr.io/pause:3.1"

EOF

cat <<EOF >/usr/lib/systemd/system/kubelet.service
[Unit]
Description=Kubernetes Kubelet
After=docker.service
Requires=docker.service

[Service]
EnvironmentFile=-/usr/local/kubernetes/cfg/kubelet
ExecStart=/usr/local/kubernetes/bin/kubelet \$KUBELET_OPTS
Restart=on-failure
KillMode=process

[Install]
WantedBy=multi-user.target
EOF

systemctl daemon-reload
systemctl enable kubelet
systemctl restart kubelet
